package cn.spream.common.util;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * URL工具类
 * Created with IntelliJ IDEA.
 * User: shaojiaxin
 * Date: 13-8-26
 * Time: 下午10:36
 * To change this template use File | Settings | File Templates.
 */
public class URLUtils {

    /**
     * 验证是否是url格式
     *
     * @param url
     * @return
     */
    public static boolean isURL(String url) {
        if (url != null && url.trim().length() > 0) {
            try {
                new URL(url);
                return true;
            } catch (MalformedURLException e) {
                //不处理
            }
        }
        return false;
    }

    /**
     * 获取url的host
     *
     * @param url
     * @return
     */
    public static String getHost(String url) {
        if (url != null && url.trim().length() > 0) {
            try {
                return new URL(url).getHost();
            } catch (MalformedURLException e) {
                //不处理
            }
        }
        return null;
    }

}
